package com.xkxbx.kkk.dyw;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.view.MotionEvent;
import android.webkit.CookieManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class TWebView extends WebView {

  public static boolean isLoad = false;

  @SuppressLint({ "JavascriptInterface", "SetJavaScriptEnabled" })
  public TWebView(Context context) {
    super(context);

    this.setWebViewClient(new WebViewClient());
    this.setWebChromeClient(new WebChromeClient());

    WebSettings settings = this.getSettings();

    settings.setSaveFormData(false);
    settings.setSavePassword(false);

    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptCookie(false);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      settings.setAllowFileAccess(true);
      settings.setAllowContentAccess(true);
      settings.setDomStorageEnabled(true);
      settings.setAppCacheEnabled(false);
    }


    settings.setJavaScriptEnabled(true);
    //①设置WebView允许调用js
    settings.setDefaultTextEncodingName("UTF-8");

    //        settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    settings.setCacheMode(BuildConfig.CACHE_MODE);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    //        this.addJavascriptInterface(new JsExtends(),"extends");
  }

  @Override
  public boolean onTouchEvent(MotionEvent event) {
    //        System.out.println(event.getAction());
    if (event.getAction() == 0) {
      //            long now = System.currentTimeMillis();
      //            String cmd =  "javascript:onTouch("+event.getAction()+","+now+")";
      //            System.out.println(now + ":" + cmd);
      //            this.loadUrl(cmd);

      //            this.reload();
    }

    return super.onTouchEvent(event);
  }
}
